package com.data.job;

import cn.hutool.core.date.DateUtil;
import com.data.pojo.StockCode;
import com.data.service.StockCodeService;
import com.data.service.StockDataService;
import com.data.util.CommonUtil;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

/**
 * @Author Str
 * @Date 2022/2/16 23:41
 * @Description :股票数据定时任务
 */
public class StockDataQuartz extends QuartzJobBean {
    @Autowired
    private StockDataService stockDateService;
    @Autowired
    private StockCodeService stockCodeService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {
        System.out.println("定时启动：" + DateUtil.now());


        // 获取所有需要进行定时任务的股票代码
        Map<String, StockCode> stockCode = stockCodeService.getStockCode();
        if (stockCode != null) {
            // 根据所有股票代码，更新股票信息（5年）
            for (String code : stockCode.keySet()) {
                stockDateService.putStockData(code, CommonUtil.getLastDate(5), CommonUtil.getNowDate());
            }
        }

        System.out.println("定时结束：" + DateUtil.now());
    }
}
